package com.zfh.cloud.controller;

import com.zfh.cloud.mapper.OrderMapper;
import com.zfh.cloud.pojo.Order;
import com.zfh.cloud.pojo.User;
import com.zfh.cloud.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 小可乐$ on 2024/9/13$ 19:30$
 * description: order的controller层
 */
@RestController
public class OrderController {
    @Autowired
    private OrderService service;

    @Value("${server.port}")
    private String port;

    @PostMapping(value = "/order/add")
    public boolean addOrder(@RequestBody Order order){
        return service.save(order);
    }

    @GetMapping(value = "/order/get/{orderId}")
    public Order findOrderByOrderId(@PathVariable("orderId") Long orderId) {
        System.out.println("----Order Module port: "+port);
        Order retValue = service.getById(orderId);
        retValue.setExtrainfo(retValue.getExtrainfo()+" \t 服务端口:"+port);
        return retValue;
    }

    /**
     * 查看订单拥有者信息
     * @param orderId
     * @return
     */
    @GetMapping(value = "/order/owner/{id}")
    public User findOrderOwner(@PathVariable("id") Long orderId) {
        return service.findOrderOwner(orderId);
    }
}

